package com.hspedu.set_;

import java.util.HashSet;
import java.util.Objects;

/**
 * @author 谷其昊
 * @version 1.0
 * @date 2022/2/8
 * @time 18:22
 */
public class HashSetExercise {
    public static void main(String[] args) {
        Employee jack = new Employee("jack", 19);
        Employee jack2 = new Employee("jack", 19);
        HashSet hs = new HashSet();
        hs.add(jack);
        hs.add(jack2);

        System.out.println("hs = " + hs.toString());
    }
}

class Employee{
    private String name;
    private int age;

    @Override
    public String toString() {
        return "Employee{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    public Employee(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Employee employee = (Employee) o;
        return age == employee.age &&
                Objects.equals(name, employee.name);
    }



    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }
}
